home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / DSMODS / IFOUT.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  14.6 KB  |  596 lines

  1. #include    <obdefs.h>
  2. #include    <gemdefs.h>
  3. #include    "comp.h"
  4. #include    "bitmap.h"        /* defs structure bit_map_type    */
  5. #include    "cache.h"        /* defs cache structure        */
  6.  
  7. /*
  8.     Local Definitions
  9. */
  10. #ifndef        FALSE
  11. #define        FALSE        0
  12. #endif
  13. #ifndef        TRUE
  14. #define        TRUE        1
  15. #endif
  16. #define        OFF        0
  17. #define        ON        1
  18. #define        H_PICA        216    /* X unit used in world Coord.    */
  19. #define        V_PICA        192    /* Y unit used in world Coord.    */
  20. #define        ULG        unsigned long
  21.  
  22. /*    Device Type = sdevm    */
  23. #define        DNUM        4    /* number of graphics devices    */
  24. #define        SLOR        0    /* Low    Res    320  x 200     */
  25. #define        SMDR        1    /* Medium Res    640  x 200     */
  26. #define        SHIR        2    /* High   Res    640  x 400    */
  27. #define        PRNT        3    /* Laser  Ptr    2400 x 3180    */
  28.  
  29. /*
  30.     Externals
  31. */
  32. extern    struct bit_map_type
  33.             *fm_char();    /* IFont char building function    */
  34. extern    struct slvll    *slv;        /* slave list pointer        */
  35. extern    int        shandle;    /* graphics output handle    */
  36. extern    FDB        *orect_MFDB;    /* output rectangle    MFDB    */
  37. extern    FDB        char_MFDB;    /* Intellifont        MFDB    */
  38. extern    unsigned long    last_y;
  39. extern    int        clip_X0;    /* output rectangle clip X0    */
  40. extern    int        clip_X1;    /* output rectangle clip X1    */
  41. extern    int        clip_Y0;    /* output rectangle clip Y0    */
  42. extern    int        clip_Y1;    /* output rectangle clip Y1    */
  43.  
  44. extern int mu_array[];             /* CS mu conversion array       */
  45. unsigned     lastpixy;
  46. unsigned    lastmuy;
  47.  
  48. /*
  49.     Conflict resolution
  50. */
  51. unsigned    get_argument();
  52.  
  53. /*
  54.     Device dependent tables
  55. */
  56. unsigned xdpi[DNUM]    = {        /* Device Xdots/inch resolution    */
  57. /* LOW */    40,            /* 320 x 200    */
  58. /* MED */    80,            /* 640 x 200    */
  59. /* HIG */    80,            /* 640 x 400    */
  60. /* PRT */    300            /* 2400x3180    */
  61. };
  62. unsigned ydpi[DNUM]    = {        /* Device Ydots/inch resolution    */
  63. /* LOW */    40,            /* 320 x 200    */
  64. /* MED */    40,            /* 640 x 200    */
  65. /* HIG */    80,            /* 640 x 400    */
  66. /* PRT */    300            /* 2400x3180    */
  67. };
  68.  
  69. /*
  70.     Module globals
  71. */
  72. struct packet_type    userpacket;/* IFont character packet    */
  73. static    struct {
  74.     unsigned    x    ;
  75.     unsigned    y    ;
  76.     unsigned    psiz    ;
  77.     unsigned    ssiz    ;
  78.     unsigned    font    ;
  79.     unsigned    reverse    ;
  80.     unsigned    rev_top    ;
  81.     unsigned    rev_bot    ;
  82. }    present            ;/* present slave scan struct    */
  83. static    struct {
  84.     unsigned    px    ;
  85.     unsigned    py    ;
  86.     unsigned    psiz    ;
  87.     unsigned    ssiz    ;
  88.     unsigned    font    ;
  89.     char        ch    ;
  90. }    rvo            ;/* Rev Video save char struct    */
  91. static    struct    bit_map_type
  92.         Greek        ;/* IFont struct. for Greeking    */
  93. unsigned    H_MARGIN    ;/* Horizontal    Left    margin    */
  94. unsigned    V_MARGIN    ;/* Vertical    Top    margin    */
  95. unsigned    zrat        ;/* zoom ratio (100 = 100%)..    */
  96. unsigned    sdevm        ;/* Current device mode        */
  97.  
  98.  
  99. /****************************************************************
  100. *    Slave Output Handler                    *
  101. *    Desc :    This routine scans through the slave command     *
  102. *    buffer list to the end. It also calls the appropriate    *
  103. *    function to execute these commands.            *
  104. *    Calling convention :    show_slv()            *
  105. ****************************************************************/
  106. show_slv()
  107. {
  108.     struct    slvll    *pslv        ;/* present slave list pointer    */
  109.     unsigned char    *buffer_ptr    ;
  110.     unsigned    code        ;
  111.     int        index = 1    ;
  112.  
  113.   pslv = slv                ;/* set to beginning of list    */
  114.   do {                     /* for whole slave list...    */
  115.     buffer_ptr = pslv->bufptr        ;/* set slave buffer pointers    */
  116.     do {                 /* for whole buffer...        */
  117.     code = get_argument(buffer_ptr)    ;/* get the encoded word    */
  118.     if (!(code & 0xFF00))         /* check if NULL command    */
  119.         index = 1        ;
  120.     else
  121.     if ((code & 0x8080) == 0x8080)     /* check if TYP command    */
  122.         index = exe_command(buffer_ptr);
  123.     else
  124.     if (code & 0x8000)         /* check if long char format    */
  125.         index = exe_long_char(buffer_ptr);
  126.     if (index > 0)
  127.         buffer_ptr += index    ;
  128.     } while (index > 0)            ;/* continue until index < 0    */
  129.   } while (pslv = pslv->fptr)        ;/* until end of list...    */
  130. }
  131.  
  132. /****************************************************************
  133. *    Function Name :        exe_long_char()            *
  134. *    Desc :    This routine executes a long char command    *
  135. *    Calling convention :    exe_long_char(buff_ptr)        *
  136. *        unsigned char    *buff_ptr : pointer to command     *
  137. ****************************************************************/
  138. exe_long_char(buffer_ptr)
  139. unsigned char    *buffer_ptr    ;
  140. {
  141.     char     dchar        ;
  142.     unsigned position    ;
  143.  
  144.     dchar     = *(buffer_ptr++) & 0X7F;    /* get the character    */
  145.     position = get_argument(buffer_ptr);    /* get X escapement    */
  146.     rvo.px     = present.x        ;
  147.     present.x = position + H_MARGIN    ;    /* set X text position    */
  148.     if (present.reverse) {            /* check if RVO ON    */
  149.         rev_char()        ;
  150.         rvo.ch     = dchar    ;
  151.         rvo.psiz = present.psiz    ;
  152.         rvo.ssiz = present.ssiz    ;
  153.         rvo.font = present.font    ;
  154.     }
  155.     else    disp_char(dchar,present.x,present.y);
  156.     rvo.py    = present.y        ;
  157.     return(3);
  158. }
  159.  
  160. /****************************************************************
  161. *    Function Name :        rev_char()            *
  162. *    Desc :    This routine displays a reverse video char    *
  163. *    Calling convention :    rev_char()            *
  164. ****************************************************************/
  165. rev_char()
  166. {
  167.     int    x, y, w, h;
  168.  
  169.     if (rvo.px > present.x) {
  170.         x = present.x            ;
  171.         w = rvo.px - present.x        ;
  172.     }
  173.     else {
  174.         x = rvo.px            ;
  175.         w = present.x - rvo.px        ;
  176.     }
  177.     y = rvo.py - present.rev_top        ;/* cal bar position    */
  178.     if (y < 0) y = 0            ;
  179.     h = rvo.py + present.rev_bot - y    ;
  180.     if (w > 0) {
  181.         bar(x,y,w,h)            ;/* display black bar    */
  182.         if (rvo.ch) {
  183.           setptsz(rvo.psiz)        ;
  184.           setssize(rvo.ssiz)         ;
  185.           setafont(rvo.font)        ;
  186.           disp_char(rvo.ch,rvo.px,rvo.py);
  187.           setptsz(present.psiz)        ;
  188.           setssize(present.ssiz)    ;
  189.           setafont(present.font)    ;
  190.         }
  191.     }
  192. }
  193.  
  194. /************************************************************************
  195. *    Function Name :        get_argument()                *
  196. *    Desc :    This function gets the command argument and converts    *
  197. *    it to unsigned value.                        *
  198. *    Calling convention :    get_argument(value_ptr)            *
  199. *        unsigned char *value_ptr : pointer to command argument    *
  200. *    Return value :        unsigned value                *
  201. ************************************************************************/
  202. unsigned get_argument(value)
  203. unsigned char *value    ;
  204. {
  205.     union {
  206.         unsigned char    byt[2]    ;
  207.         unsigned    val    ;
  208.     } w;
  209.  
  210.     w.byt[0] = *value++,
  211.     w.byt[1] = *value        ;/* combine two together     */
  212.     return(w.val)            ;/* return the value         */
  213. }
  214.  
  215. /****************************************************************
  216. *    Function Name :        exe_command()            *
  217. *    Desc :    This routine execute the slave command        *
  218. *    Calling convention : len = exe_command(cmd_ptr)        *
  219. *        unsigned char    *cmd_ptr : pointer to command    *
  220. *    Return value    :    int command length        *
  221. ****************************************************************/
  222. exe_command(buffer_ptr)
  223. unsigned char     *buffer_ptr    ;
  224. {
  225.     unsigned char    command    ;
  226.     unsigned    argument;
  227.     int    cmd_len = 3    ;
  228.  
  229. command  = *(buffer_ptr++) & 0X7F        ;/* get command number     */
  230. argument = get_argument(buffer_ptr)        ;/* get    command arg    */
  231. argument &= 0X7FFF                ;/* mask the high bit    */
  232. switch(command) {
  233. case( 3)    :                 /* REVERSE TYPE    */
  234.     if (present.reverse)
  235.         rev_char()            ;
  236.     else    rvo.py    = present.y        ;
  237.     present.reverse = argument        ;/* set reverse type    */
  238.     if (!argument) rvo.ch = 0        ;
  239.     break                    ;
  240. case( 7)    :                 /* POINT SIZE CMD    */
  241.     setptsz(present.psiz = argument)    ;/* set char height    */
  242. case( 8)    :                 /* SET SIZE CMD    */
  243.     setssize(present.ssiz = argument)     ;/* set char width    */
  244.     break                    ;
  245. case( 9)    :                 /* VERTICAL MOVE DOWN    */
  246.     present.y += argument            ;/* adjust position    */
  247.     break                    ;
  248. case(10)    :                 /* VERTICAL MOVE UP    */
  249.     present.y -= argument            ;/* adjust position    */
  250.     break                    ;
  251. case(11)    :                 /* HORIZONTAL POSITION */
  252.     if (present.reverse)
  253.         rvo.px = present.x        ;
  254.     present.x = argument + H_MARGIN        ;/* adjust position    */
  255.     break                    ;
  256. case(15)    :                 /* SLANT MODE        */
  257.     break                    ;
  258. case(16)    :                 /* REVERSE TOP        */
  259.     present.rev_top = argument        ;/* set rev_top value    */
  260.     break                    ;
  261. case(17)    :                 /* REVERSE BOTTOM    */
  262.     present.rev_bot = argument        ;/* set rev_bot value    */
  263.     break                    ;
  264. case(22)    :                 /* SET FONT        */
  265.     setafont(present.font = argument)    ;
  266.     cmd_len = 9                ;
  267.     break                    ;
  268. case(27)    :                 /* MOVE HOR RIGHT    */
  269.     present.x += argument            ;/* adjust position    */
  270.     break                    ;
  271. case(28)    :                 /* MOVE HOR. LEFT    */
  272.     present.x -= argument            ;/* adjust position    */
  273.     break                    ;
  274. case(SLVEOD)    :                 /* END OF SLAVE DATA    */
  275. case(SLVEOB)    :                 /* END OF SLAVE BLOCK    */
  276.     cmd_len = -1                ;/* stop scanning code    */
  277.     break                    ;
  278. case(31)    :                 /* VERTICAL POSITION    */
  279.     present.y = argument + V_MARGIN        ;/* adjust position    */
  280.     break                    ;
  281. }
  282. return(cmd_len)                    ;/* return cmmnd length    */
  283. }
  284.  
  285. /*
  286.     Function to initialize IFont System
  287. */
  288. initftsys(mod)
  289. int    mod;
  290. {
  291.     if (!fm_init(mod)            /* set up Intellifont    */
  292.      || !fm_outdevice(0,xdpi[sdevm],ydpi[sdevm])    /* both screen    */
  293.      || !fm_outdevice(1,xdpi[PRNT],ydpi[PRNT]))    /* and printer    */
  294.         return(1);
  295.     else {    newdev(0);
  296.         return(0);
  297.     }
  298. }
  299.  
  300. /*
  301.     Function to set IFont system to new device
  302. */
  303. newdev(dev)
  304. int    dev;
  305. {
  306.     userpacket.p_cd.point_size    = 96;
  307.     userpacket.p_cd.set_size    = 96;
  308.     userpacket.p_cd.rotate_angle    = 0;
  309.     userpacket.p_cd.bold        = 0;
  310.     userpacket.p_cd.devnum        = dev;
  311.     userpacket.p_cd.font_id        = 1;
  312. }
  313.  
  314. /*
  315.     Function to set IFont user packet to new point size
  316. */
  317. setptsz(val)
  318. int    val;
  319. {
  320.     ssize(&userpacket.p_cd.point_size,val);
  321. }
  322.  
  323. /*
  324.     Function to set IFont user packet to new set size
  325. */
  326. setssize(val)
  327. int    val;
  328. {
  329.     ssize(&userpacket.p_cd.set_size,val);
  330. }
  331.  
  332. ssize(size,val)
  333. unsigned *size, val;
  334. {
  335.     *size = zvalue(val);
  336. }
  337.  
  338. /*
  339.     Function to set IFont user packet to new font number
  340. */
  341. setafont(val)
  342. int    val;
  343. {
  344.     userpacket.p_cd.font_id    = val;
  345. }
  346.  
  347. /*
  348.     Function to setup Greeking bitmap structure.
  349. */
  350. setupGreek()
  351. {
  352.     Greek.width    = 1;
  353.     Greek.depth    = sdevm == SMDR ? 2:4;
  354.     Greek.left_indent = 0;
  355.     Greek.base_pix    = Greek.depth;
  356.     Greek.new_lsb    = 0;
  357.     Greek.bm[0]    = 0x5000;    /* Greeking character Bit Map    */
  358.     Greek.bm[1]    = 0xA000;    /* Medium Res. only use 2 words    */
  359.     Greek.bm[2]    = 0x5000;
  360.     Greek.bm[3]    = 0xA000;
  361. }
  362.  
  363. /*
  364.     IFont character display
  365. */
  366. disp_char(dchar,dx,dy)
  367. unsigned char    dchar;
  368. unsigned    dx, dy;
  369. {
  370.     struct bit_map_type    *bmp_ptr;
  371.  
  372.     if (!dchar || dchar > 118)
  373.         return;
  374.     if (userpacket.p_cd.point_size    < 40 &&
  375.         userpacket.p_cd.set_size    < 40)    /* Greeking < 5 points    */
  376.         bmp_ptr = &Greek;
  377.     else {
  378.         userpacket.flash_pos = dchar - 1;
  379.         bmp_ptr = fm_char(&userpacket);
  380.     }
  381.     if (bmp_ptr) blt_char(bmp_ptr, dx, dy);
  382. }
  383.  
  384. /********************************/
  385. /*    grect_to_array        */
  386. /********************************/
  387. grect_to_array(area, array)    /* convert x,y,w,h to upr lt x,y and    */
  388. GRECT     *area;            /*              lwr rt x,y    */
  389. unsigned *array;
  390. {
  391.     *array++= area->g_x;
  392.     *array++= area->g_y;
  393.     *array++= area->g_x + area->g_w - 1;
  394.     *array    = area->g_y + area->g_h - 1;
  395. }
  396.  
  397. /********************************/
  398. /*    raster_operation    */
  399. /********************************/
  400. rast_op(mode, s_area, s_MFDB, d_area, d_MFDB)    /* bit block level Xfer    */
  401. unsigned mode;
  402. GRECT    *s_area, *d_area;
  403. FDB    *s_MFDB, *d_MFDB;
  404. {
  405.     unsigned pxy[8];
  406.  
  407.     grect_to_array(s_area, pxy);
  408.     grect_to_array(d_area, &pxy[4]);
  409.     vro_cpyfm(shandle,mode,pxy,s_MFDB,d_MFDB);
  410. }
  411.  
  412. /********************************/
  413. /*    IFont char Blit        */
  414. /********************************/
  415. blt_char(bptr,x,y)
  416. struct bit_map_type    *bptr;
  417. unsigned        x, y;
  418. {
  419.     GRECT    s, d;
  420.     int    ref, IFcw, IFch;
  421.  
  422.     ref    = world_convert(x);
  423.     d.g_x    = ref + (bptr->new_lsb >> 4) - bptr->left_indent;
  424.     IFcw    = bptr->width << 4;
  425.     if (d.g_x < clip_X0) {
  426.         s.g_x = clip_X0 - d.g_x;
  427.         d.g_x = clip_X0;
  428.     }
  429.     else    s.g_x = 0;
  430.     ref    = IFcw - s.g_x;
  431.     if (ref <= 0)    return;
  432.     if ((d.g_w = clip_X1 - d.g_x) >= ref)
  433.         d.g_w = s.g_w = ref;
  434.     else
  435.     if (d.g_w <= 0) return;
  436.     else    s.g_w = d.g_w;
  437.         if(y == lastmuy)        /* If we're on the same line we.. */
  438.             ref = lastpixy;        /* don't have to recalculate y .. */
  439.         else                /* pixel position          */
  440.     {
  441.             lastmuy = y;
  442.         ref = lastpixy = world_rc_y(y);
  443.     }
  444.     d.g_y    = ref - bptr->base_pix;
  445.     IFch    = bptr->depth;
  446.     if (d.g_y < clip_Y0) {
  447.         s.g_y = clip_Y0 - d.g_y;
  448.         d.g_y = clip_Y0;
  449.     }
  450.     else    s.g_y = 0;
  451.     ref    = IFch - s.g_y;
  452.     if (ref <= 0)    return;
  453.     if ((d.g_h = clip_Y1 - d.g_y) >= ref)
  454.         d.g_h = s.g_h = ref;
  455.     else
  456.     if (d.g_h <= 0) return;
  457.     else    s.g_h = d.g_h;
  458.  
  459.     char_MFDB.fd_addr    = (ULG)bptr->bm;
  460.     char_MFDB.fd_w        = IFcw;
  461.     char_MFDB.fd_h        = IFch;
  462.     char_MFDB.fd_wdwidth    = bptr->width;
  463.     rast_op((present.reverse) ? 4:7,&s,&char_MFDB,&d,orect_MFDB);
  464. }
  465.  
  466. /****************************************/
  467. /*    Draw Bar using world values    */
  468. /****************************************/
  469. bar(x,y,w,h)
  470. unsigned x,y,w,h;
  471. {
  472.     GRECT    rul;
  473.     int    ref;
  474.  
  475.     rul.g_x = world_rc_x(x);
  476.     w    = world_rc_x(w) + 1;
  477.     if (rul.g_x < clip_X0) {
  478.         ref = clip_X0 - rul.g_x;
  479.         rul.g_x = clip_X0;
  480.     }
  481.     else    ref = 0;
  482.     w    -= ref;
  483.     if (w <= 0)    return;
  484.     if ((rul.g_w = clip_X1 - rul.g_x) > w)
  485.         rul.g_w = w;
  486.     else
  487.     if (rul.g_w <= 0) return;
  488.  
  489.     rul.g_y = world_rc_y(y);
  490.     h    = world_rc_y(h) + 1;
  491.     if (rul.g_y < clip_Y0) {
  492.         ref = clip_Y0 - rul.g_y;
  493.         rul.g_y = clip_Y0;
  494.     }
  495.     else    ref = 0;
  496.     h    -= ref;
  497.     if (h <= 0)    return;
  498.     if ((rul.g_h = clip_Y1 - rul.g_y) > h)
  499.         rul.g_h = h;
  500.     else
  501.     if (rul.g_h <= 0) return;
  502.  
  503.     rast_op(15,&rul,orect_MFDB,&rul,orect_MFDB);
  504. }
  505.  
  506. /****************************************/
  507. /*    X world value to X R.C value    */
  508. /****************************************/
  509.  
  510. world_convert(x)
  511. unsigned x;
  512. {
  513.    switch(zrat)
  514.    {
  515.     case 100:
  516.        if(sdevm == 3)
  517.         return(world_rc_x(x));
  518.        else
  519.         return(mu_array[x]);
  520.        break;
  521.     case 50:
  522.        x /= 2;
  523.        return(mu_array[x]);
  524.        break;
  525.     case 75:
  526.        x *= 3;
  527.        x /= 4;
  528.        return(mu_array[x]);
  529.        break;
  530.     default:
  531.        return(world_rc_x(x));
  532.        break;
  533.    }
  534. }
  535.  
  536. world_rc_x(x)
  537. unsigned x;
  538. {
  539.     ULG    temp;
  540.     x = zvalue(x);
  541.     temp = (ULG)xdpi[sdevm] * (ULG)x;
  542.     x = ((temp % 1296L) > 648L);
  543.     temp /= 1296L;
  544.     return((unsigned)temp + x);
  545. }
  546.  
  547. /****************************************/
  548. /*    Y world value to Y R.C value    */
  549. /****************************************/
  550. world_rc_y(y)
  551. unsigned y;
  552. {
  553.     ULG    temp;
  554.     y = zvalue(y);
  555.     temp = (ULG)ydpi[sdevm] * (ULG)y;
  556.     y = ((temp % 1152L) > 576L);
  557.     temp /= 1152L;
  558.     return((unsigned)temp + y);
  559. }
  560.  
  561. /****************************************
  562. *    Zoom value convert function    *
  563. ****************************************/
  564. zvalue(n)
  565. unsigned n;
  566. {
  567.     ULG    temp;
  568.     if (zrat == 100) return(n);
  569.     temp = (ULG)zrat * (ULG)n;
  570.     n = ((temp % 100L) > 50L);
  571.     temp /= 100L;
  572.     return((unsigned)temp + n);
  573. }
  574.  
  575. resetIFpos()
  576. {
  577.         lastmuy = lastpixy = 0;
  578.     last_y        = 0L;
  579.     present.x    = H_MARGIN,
  580.     present.y    = V_MARGIN;    /* reset the text positions    */
  581.     present.reverse = 0,
  582.     present.rev_top = 0,
  583.     present.rev_bot = 0;        /* init reverse type OFF    */
  584.     rvo.ch        = 0;
  585.     rvo.py        = present.y;
  586. }
  587.  
  588.  
  589. setYpos(ypos)
  590. unsigned ypos;
  591. {
  592.     present.y = ypos;
  593.     rvo.py      = present.y;
  594. }
  595.  
  596.